from util.db import DBManager
from business import Business
from util.web.session import ErrException


def select(db_manager: DBManager, sql):
    with db_manager:
        return db_manager.select(sql)


def execute(db_manager: DBManager, sql):
    with db_manager:
        return db_manager.execute(sql)


def insert(db_manager: DBManager, sql):
    with db_manager:
        return db_manager.insert(sql)


def clear(db_manager: DBManager, business: Business, password: str):
    if password != '123456':
        raise ErrException(err_code=500, err_msg="密码错误!")
    with db_manager:
        return db_manager.execute("truncate `distributes`")
